package com.ysstech.kettle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ysstech.kettle.entity.JobDatasource;
import com.ysstech.kettle.entity.JobTaskDetails;
import com.ysstech.kettle.mapper.JobTaskDetailsMapper;
import com.ysstech.kettle.service.JobDatasourceService;
import com.ysstech.kettle.service.JobTaskDetailsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lishuangliang
 * @since 2022-10-11
 */
@Service
public class JobTaskDetailsServiceImpl extends ServiceImpl<JobTaskDetailsMapper, JobTaskDetails> implements JobTaskDetailsService {

    @Autowired
    private JobDatasourceService jobDatasourceService;

    public List<JobTaskDetails> listInfo(String taskId) throws Exception {
        QueryWrapper<JobTaskDetails> wrapper = new QueryWrapper<>();
        wrapper.eq("TASK_ID", taskId);
        wrapper.orderByAsc("SEQUENCE");
        List<JobTaskDetails> list = this.list(wrapper);
        List<JobDatasource> datasourceList = jobDatasourceService.list();
        Map<String, String> map = new HashMap<>();
        for (JobDatasource jobDatasource : datasourceList) {
            map.put(jobDatasource.getId(), jobDatasource.getName());
        }
        for (JobTaskDetails jobTaskDetails : list) {
            jobTaskDetails.setInputDataName(map.get(jobTaskDetails.getInputDataId()));
            jobTaskDetails.setOutputDataName(map.get(jobTaskDetails.getOutputDataId()));
        }
        return list;
    }
}
